package com.gydz.gydzbaseframeworkboot.gsCenter.controller;

import com.gydz.gydzbaseframeworkboot.common.utils.page.PageParam;
import com.gydz.gydzbaseframeworkboot.common.utils.page.PageUtils;
import com.gydz.gydzbaseframeworkboot.common.utils.page.TableDataInfo;
import com.gydz.gydzbaseframeworkboot.common.utils.result.ResultUtils;
import com.gydz.gydzbaseframeworkboot.gsCenter.dao.GsmasterMapper;
import com.gydz.gydzbaseframeworkboot.gsCenter.domain.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
public class UserInfoController {

    @Autowired
    GsmasterMapper gsmasterMapper;

    @GetMapping("/userCenter/list")
    public ModelAndView userModelAndView(ModelAndView modelAndView) {
        modelAndView.setViewName("userCenter/list");
        return modelAndView;
    }


    @ResponseBody
    @RequestMapping("/user/list")
    @PreAuthorize("hasAuthority('admin') or hasAuthority('test')" )
    public void getUserInfo(HttpServletRequest request , HttpServletResponse httpServletResponse, @ModelAttribute("userInfo") UserInfo userInfo) throws IOException {
        PageUtils.startPage(new PageParam(userInfo.getiDisplayStart(),userInfo.getiDisplayLength(),userInfo.getsSortDir(),userInfo.getsSortCol()));
        List<UserInfo> userInfoList = gsmasterMapper.userList(userInfo);
        TableDataInfo tableDataInfo = PageUtils.getDataTable(userInfoList);
        ResultUtils result =  ResultUtils.succ(200,"获取用户信息成功",tableDataInfo);
        ResultUtils.responseResult(httpServletResponse,result);
    }
}
